//
//  GushiTableViewCell.m
//  XRSquare
//
//  Created by 穆相臣 on 2018/10/28.
//  Copyright © 2018 UaenaMo. All rights reserved.
//

#import "GushiTableViewCell.h"

@interface GushiTableViewCell ()
{
    UILabel * lable;
    UIImageView * image1;
    UIImageView * image2;
    UIImageView * image3;
    UIImageView * image4;
}
@end

@implementation GushiTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        lable = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, ScreenWidth - 20, 20)];
        lable.font = [UIFont systemFontOfSize:15];
        lable.numberOfLines = 0;
        [self addSubview:lable];
        
        image1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 40, (ScreenWidth - 40)/4, (ScreenWidth - 40)/4)];
        [self addSubview:image1];
        
        image2 = [[UIImageView alloc]initWithFrame:CGRectMake(10 + (ScreenWidth - 40)/4 + 5, 40, (ScreenWidth - 40)/4, (ScreenWidth - 40)/4)];
        [self addSubview:image2];
        
        image3 = [[UIImageView alloc]initWithFrame:CGRectMake(10 + (ScreenWidth - 40)/4 * 2 + 10, 40, (ScreenWidth - 40)/4, (ScreenWidth - 40)/4)];
        [self addSubview:image3];
        
        image4 = [[UIImageView alloc]initWithFrame:CGRectMake(10 + (ScreenWidth - 40)/4 * 3 + 15, 40, (ScreenWidth - 40)/4, (ScreenWidth - 40)/4)];
        [self addSubview:image4];
    }
    return self;
}

+(CGFloat)heightWithData:(NSDictionary *)data
{
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth - 20, 20)];
    label.font = [UIFont systemFontOfSize:15];
    label.numberOfLines = 0;
    label.text = [data objectForKey:@""];
    [label sizeToFit];
    
    NSArray * img = [data objectForKey:@""];
    if ([img count])
    {
        return label.frame.size.height + 20 + (ScreenWidth - 40)/4 + 10;
    }
    else
    {
        return label.frame.size.height + 20;
    }
    
}

-(void)loadData:(NSDictionary *)data
{
    lable.frame = CGRectMake(10, 10, ScreenWidth - 20, 20);
    NSArray * images = [data objectForKey:@""];
    switch ([images count]) {
        case 4:
            [image4 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[images objectAtIndex:3]]]];
        case 3:
            [image3 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[images objectAtIndex:2]]]];
        case 2:
            [image2 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[images objectAtIndex:1]]]];
        case 1:
            [image1 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[images objectAtIndex:0]]]];
        default:
            break;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
